package v4.file;

public class XorKit {
	
	public static void xor(byte[] buf, int bufLen, byte[] key, long pos, int jump) {
		for(int i=0; i<bufLen; i++){
			buf[i] = (byte) (buf[i] ^ getBit(key, i + pos, jump));
		}
	}
	
	private static byte getBit(byte[] key, long pos, int jump) {
		if(jump>0) {
			if(pos % jump == 0) {
				return 1;
			}
		}
		int j = (int) (pos % key.length);
		return key[j];
	}

	public static void xor(byte[] buf, int bufLen, byte[] key, long pos) {
		for(int i=0; i<bufLen; i++){
			buf[i] = (byte) (buf[i] ^ getBit(key, i + pos, 0));
		}
	}
	
}
